package edu.thu.studio.ormdesigner.editor.command;

import edu.thu.studio.ormdesigner.common.AbstractCommand;
import edu.thu.studio.ormdesigner.model.diagram.link.Link;

public class DeleteLinkCommand extends AbstractCommand {
    
    private Link link;
    
    public DeleteLinkCommand(Link connection) {
        this.link = connection;
    }
    
    /**
     * {@inheritDoc}
     */
    @Override
    protected void doExecute() {
        this.link.disconnect();
        this.link.getTarget().refreshTargetConnections();
        this.link.getSource().refreshSourceConnections();
    }
    
    /**
     * {@inheritDoc}
     */
    @Override
    protected void doUndo() {
        this.link.reconnect();
        
        this.link.getTarget().refreshTargetConnections();
        this.link.getSource().refreshSourceConnections();
    }
}
